home *** CD-ROM | disk | FTP | other *** search
/ Stone Design / Stone Design.iso / Stone_Friends / Wave / WavesWorld / Source / IBPalettes / WW3DKit / RIBTransform.m < prev    next >
Encoding:
Text File  |  1995-03-22  |  4.7 KB  |  209 lines

  1. // copyright 1993 Michael B. Johnson; some portions copyright 1994, MIT
  2. // see COPYRIGHT for reuse legalities
  3. //
  4.  
  5. #import "RIBTransform.h"
  6.  
  7. @implementation RIBTransform
  8.  
  9. + initialize { return [RIBTransform setVersion:1], self; }
  10.  
  11. - init
  12. {
  13.   [super init];
  14.   N3D_CopyMatrix(N3DIdentityMatrix, aMatrix);
  15.  
  16.   return self;
  17. }
  18.  
  19. - setMatrix:(RtMatrix)newMatrix
  20. {
  21.   N3D_CopyMatrix(newMatrix, aMatrix);
  22.   return self;
  23. }
  24.  
  25. - getMatrix:(RtMatrix *)matrixPtr
  26. {
  27.   N3D_CopyMatrix(aMatrix, *matrixPtr);
  28.   return self;
  29. }
  30.  
  31. - (BOOL)theSameAs:otherRIBCommand
  32. {
  33.   RtMatrix  otherMatrix;
  34.  
  35.  
  36.   [otherRIBCommand getMatrix:&otherMatrix];
  37.  
  38.   if (aMatrix[0][0] != otherMatrix[0][0])
  39.   {  return NO;
  40.   }
  41.   if (aMatrix[0][1] != otherMatrix[0][1])
  42.   {  return NO;
  43.   }
  44.   if (aMatrix[0][2] != otherMatrix[0][2])
  45.   {  return NO;
  46.   }
  47.   if (aMatrix[0][3] != otherMatrix[0][3])
  48.   {  return NO;
  49.   }
  50.  
  51.   if (aMatrix[1][0] != otherMatrix[1][0])
  52.   {  return NO;
  53.   }
  54.   if (aMatrix[1][1] != otherMatrix[1][1])
  55.   {  return NO;
  56.   }
  57.   if (aMatrix[1][2] != otherMatrix[1][2])
  58.   {  return NO;
  59.   }
  60.   if (aMatrix[1][3] != otherMatrix[1][3])
  61.   {  return NO;
  62.   }
  63.  
  64.   if (aMatrix[2][0] != otherMatrix[2][0])
  65.   {  return NO;
  66.   }
  67.   if (aMatrix[2][1] != otherMatrix[2][1])
  68.   {  return NO;
  69.   }
  70.   if (aMatrix[2][2] != otherMatrix[2][2])
  71.   {  return NO;
  72.   }
  73.   if (aMatrix[2][3] != otherMatrix[2][3])
  74.   {  return NO;
  75.   }
  76.  
  77.   if (aMatrix[3][0] != otherMatrix[3][0])
  78.   {  return NO;
  79.   }
  80.   if (aMatrix[3][1] != otherMatrix[3][1])
  81.   {  return NO;
  82.   }
  83.   if (aMatrix[3][2] != otherMatrix[3][2])
  84.   {  return NO;
  85.   }
  86.   if (aMatrix[3][3] != otherMatrix[3][3])
  87.   {  return NO;
  88.   }
  89.  
  90.   return [super theSameAs:otherRIBCommand];
  91. }
  92.  
  93. - renderSelf:(WW3DCamera *)camera startingAt:(RtFloat)shutterOpenTime endingAt:(RtFloat)shutterCloseTime
  94. {
  95.   RiTransform(aMatrix);
  96.  
  97.   return self;
  98. }
  99.  
  100. - transformCTM:(WW3DAttributeState *)attributeState startingAt:(RtFloat)shutterOpenTime endingAt:(RtFloat)shutterCloseTime
  101.   [attributeState setTransformMatrix:aMatrix];
  102.   return self; 
  103. }
  104.  
  105. - (BOOL)isMotionBlurrable { return YES; }
  106.  
  107. - (unsigned long int)maxSampleBandwidth {  return ([super maxSampleBandwidth] + (unsigned long int)(16 * sizeof(RtFloat))); }
  108.  
  109. - writeEve:(NXStream *)stream atTabLevel:(int)tab
  110. {
  111.    int  i;
  112.  
  113.  
  114.    for (i = 0; i < tab; i++)
  115.    {  NXPrintf(stream, "\t");
  116.    }
  117.    NXPrintf(stream, "Transform {");
  118.    NXPrintf(stream, "%f %f %f %f ",  aMatrix[0][0], aMatrix[0][1], aMatrix[0][2], aMatrix[0][3]);
  119.    NXPrintf(stream, "%f %f %f %f ",  aMatrix[1][0], aMatrix[1][1], aMatrix[1][2], aMatrix[1][3]);
  120.    NXPrintf(stream, "%f %f %f %f ",  aMatrix[2][0], aMatrix[2][1], aMatrix[2][2], aMatrix[2][3]);
  121.    NXPrintf(stream, "%f %f %f %f};", aMatrix[3][0], aMatrix[3][1], aMatrix[3][2], aMatrix[3][3]);
  122.    NXPrintf(stream, "; ");
  123.  
  124.    return self;
  125. }
  126.  
  127.  
  128. - writeInventorAtTime:(float)currentTime to:(NXStream *)stream atTabLevel:(int)tab
  129. {
  130.    int  i;
  131.  
  132.  
  133.    for (i = 0; i < tab; i++)
  134.    {  NXPrintf(stream, "\t");
  135.    }
  136.    NXPrintf(stream, "ResetTransform {\n");
  137.    for (i = 0; i < (tab+1); i++)
  138.    {  NXPrintf(stream, "\t");
  139.    }
  140.    NXPrintf(stream, "whatToTransform TRANSFORM\n");
  141.    for (i = 0; i < tab; i++)
  142.    {  NXPrintf(stream, "\t");
  143.    }
  144.    NXPrintf(stream, "}\n");
  145.    for (i = 0; i < tab; i++)
  146.    {  NXPrintf(stream, "\t");
  147.    }
  148.    NXPrintf(stream, "MatrixTransform {\n");
  149.    for (i = 0; i < (tab+1); i++)
  150.    {  NXPrintf(stream, "\t");
  151.    }
  152.    NXPrintf(stream, "matrix %f %f %f %f\n", aMatrix[0][0], aMatrix[0][1], aMatrix[0][2], aMatrix[0][3]);
  153.    for (i = 0; i < (tab+1); i++)
  154.    {  NXPrintf(stream, "\t");
  155.    }
  156.    NXPrintf(stream, "       %f %f %f %f\n",  aMatrix[1][0], aMatrix[1][1], aMatrix[1][2], aMatrix[1][3]);
  157.    for (i = 0; i < (tab+1); i++)
  158.    {  NXPrintf(stream, "\t");
  159.    }
  160.    NXPrintf(stream, "       %f %f %f %f\n",  aMatrix[2][0], aMatrix[2][1], aMatrix[2][2], aMatrix[2][3]);
  161.    for (i = 0; i < (tab+1); i++)
  162.    {  NXPrintf(stream, "\t");
  163.    }
  164.    NXPrintf(stream, "       %f %f %f %f\n", aMatrix[3][0], aMatrix[3][1], aMatrix[3][2], aMatrix[3][3]);
  165.    for (i = 0; i < tab; i++)
  166.    {  NXPrintf(stream, "\t");
  167.    }
  168.    NXPrintf(stream, "}");
  169.  
  170.    return self;
  171.  
  172. }
  173.  
  174.  
  175. - read:(NXTypedStream*)stream 
  176. {
  177.     int version;
  178.     [super read:stream];
  179.  
  180.     version = NXTypedStreamClassVersion(stream,"RIBTransform");
  181.     if (version == 0) NXReadTypes(stream,"i",&version), version=1;
  182.     if (version == 1)
  183.     {  NXReadArray(stream, "f", 4, aMatrix[0]);
  184.        NXReadArray(stream, "f", 4, aMatrix[1]);
  185.        NXReadArray(stream, "f", 4, aMatrix[2]);
  186.        NXReadArray(stream, "f", 4, aMatrix[3]);
  187.     } 
  188.     else 
  189.     {
  190.     }
  191.     return self;
  192. }
  193.  
  194. - write:(NXTypedStream*)stream 
  195. {
  196.     [super write:stream];
  197.  
  198.     NXWriteArray(stream, "f", 4, aMatrix[0]);
  199.     NXWriteArray(stream, "f", 4, aMatrix[1]);
  200.     NXWriteArray(stream, "f", 4, aMatrix[2]);
  201.     NXWriteArray(stream, "f", 4, aMatrix[3]);
  202.  
  203.     return self;
  204. }
  205.  
  206.  
  207. @end
  208.